package com.bjpowernode.javase.collection;
/*
集合使用foreach
 */
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
public class ForEachTest02 {
    public static void main(String[] args) {
        List<String> strList = new ArrayList<>();
        strList.add("hello");
        strList.add("world");
        strList.add("kitty");

        //遍历：使用迭代器
        Iterator it = strList.iterator();
        while(it.hasNext()){
            System.out.println(it.next());
        }

        //遍历：get()方法
        for(int i = 0;i<strList.size();i++){
            System.out.println(strList.get(i));
        }

        //遍历：使用foreach
        for(String data:strList){
            System.out.println(data);
        }

        List<Integer> list = new ArrayList<>();
        list.add(10);
        list.add(100);
        list.add(1000);

        for(Integer i:list){
            System.out.println(i);
        }
    }
}
